function [r_times, ir_val, r_val] = strescint(jmptimes, fval, ...
                                       tm_scale, sp_scale, b_verb) 

% STRESCINT Rescale and integrate a piecewice constant function:
%
%      g(t) = a/b * int^t f(as) ds. 
%
% The function is given by two vectors containing the jumps points
% and function values at these points respectively. The result is a
% piecewise linear function. If several scales are given, then
% the resulting processes are stored as column vectors in two
% matrices and truncated at a largest common time. 
%
% The result is the same as that of STINTRESC, but this function is
% faster. The reason is that the integrated piecewise constant
% function is piecewise linear and the truncation operation for the
% latter is more complex.
%
%  [r_times, ir_val, r_val] = strescint(jmptimes, fval, 
%                                      tm_scale, sp_scale, b_verb)
% Inputs: 
%        jmptimes - a vector of the jump points 
%        fval - a vector of function values at the jump points
%        tm_scale - a column vector of "time" scales, parameter [a]
%          above 
%        sp_scale - a column vector of "space" scales, parameter [b]
%          above 
%        b_verb - if 1 then print processing info
%
% Outputs:
%        r_times - a column vector(s) of the break times of the
%          integrated and rescaled function(s) 
%        ir_val - a column vector(s) of values at the break times
%          of the rescaled and integrated function(s) 
%        r_val - a column vector of values at the break times
%          of the rescaled function before integration
%
% See also STINTRESC, SCALEMGINFTY, SCALEONOFF.

% Authors: R.Gaigalas, I.Kaj
% v1.0 03-Oct-05

  % rescale time
  % X(at) jumps at t_n/a
  r_times = jmptimes*(1./tm_scale)';
  % rescale space; multiply by the time scale to compensate for the
  % change of variables 
  r_val = fval*(tm_scale./sp_scale)';
  
  % cut the piecewise constant processes at the largest common time
  cut_time = min(r_times(end, 1:end));
  [r_times r_val] = staircut(r_times, r_val, cut_time);

  % integrate the rescaled and centered system size process
  ir_val = stairintegr(r_times, r_val);

  if b_verb % print info
    fprintf(1, '##Largest common time window: %f\n', cut_time);
  end  
